// src/store/modules/user.js
const state = {
  token: '',
  userInfo: {}
}

const mutations = {
  SET_TOKEN(state, token) {
    state.token = token
  },
  SET_USERINFO(state, userInfo) {
    state.userInfo = userInfo
  }
}

const actions = {
  login({ commit }, token) {
    commit('SET_TOKEN', token)
    localStorage.setItem('token', token)
  },
  logout({ commit }) {
    commit('SET_TOKEN', '')
    commit('SET_USERINFO', {})
    localStorage.removeItem('token')
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}